package com.jye.rseven.user;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@SpringBootApplication
public class R7UserWebApplication {

	public static void main(String[] args) {
		SpringApplication.run(R7UserWebApplication.class, args);
	}


	@Bean(name = "delayOrderExecutor")
	ExecutorService getOrderThreadPoolForDelayQueue() {
		return new ThreadPoolExecutor(1, 1,
				0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
				new ThreadFactoryBuilder().setNameFormat("DelayOrder-%d").setDaemon(true).build(),
				new ThreadPoolExecutor.CallerRunsPolicy());
	}
}
